import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class MilestoneView extends JPanel{
	
	private Image img;
	private MilestoneModel mm;
	private MapController mpc;
	private JLabel Name, typeLabel, storeLabel, distanceLabel;
	private String milestone, type, store, distance;
	private int typeCheck;
	private boolean storeCheck;
	private double distanceCheck;

	  public MilestoneView(Image img, MilestoneModel mm, MapController mpc) {
	    this.img = img;
	    this.mm = mm;
	    this.mpc = mpc;
	    setSize(350, 265);
	    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	    
	    mm = new MilestoneModel();
	    milestone = mm.getName(mpc.getNextIndex());
	    
	    JLabel Name = new JLabel("Next Milestone: "+milestone);
	    Name.setAlignmentX(JLabel.CENTER_ALIGNMENT);
		Name.setFont(new Font("Tahoma", Font.BOLD, 12));
		
		add(Box.createRigidArea(new Dimension(350, 5)));
		add(Name);
		
		typeCheck = mm.getType(mpc.getNextIndex());
		if(typeCheck==0){
			type = "City";
		}
		else{
			type = "River";
		}
		
		storeCheck = mm.getStore(mpc.getNextIndex());
		if(storeCheck){
			store = "Yes";
		}
		else{
			store = "No";
		}
		
		distanceCheck = Math.sqrt(Math.pow(mm.getSpotX(mpc.getNextIndex())-mpc.getPlayerX(), 2) + Math.pow(mm.getSpotY(mpc.getNextIndex())-mpc.getPlayerY(), 2));
		if(distanceCheck<=10){
			distance = "close";
		}
		else if(distanceCheck>=10&&distanceCheck<=20){
			distance = "approaching";
		}
		else{
			distance = "far";
		}
		
		typeLabel = new JLabel(" Type: "+type);
		typeLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
		storeLabel = new JLabel(" Store: "+store);
		storeLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
		distanceLabel = new JLabel(" Distance: "+distance);
		distanceLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
		
		add(Box.createRigidArea(new Dimension(350, 187)));
		add(typeLabel);
		add(storeLabel);
		add(distanceLabel);
	  }

	  public void paintComponent(Graphics g) {	    
	    g.setColor(new Color(255, 220, 51));
	    g.fillRect(0, 0, 350, 270);
	    g.drawImage(img, 25, 25, null);
	  }
	  
}
